/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2024-2024. All rights reserved.
 *
 */

import { HosSdkVersion, HosVersionMapper } from '@ohos/hos-sdkmanager-common';

export class VersionConst {
  static readonly SUPPORT_COMPILE_VERSION: string = getHosCompileVersion();

  static readonly MINIMUM_COMPATIBLE_VERSION: string = '4.0.0(10)';

  static readonly ATOMIC_SERVICE_MINIMUM_COMPATIBLE_VERSION: string = '4.1.0(11)';

  static readonly CURRENT_MODEL_VERSION: string = getCurrentModelVersion();

  static readonly MINIMUM_MODEL_VERSION: string = '5.0.0';
}

/**
 * 从sdk-manager获取当前配套的compileVersion
 *
 * @return string 版本号信息, 如"5.0.0(12)"
 */
function getHosCompileVersion(): string {
  const hosSdkVersion: HosSdkVersion = getLatestSupportVersion();
  return `${hosSdkVersion.getPlatformVersion().getVersion()}(${hosSdkVersion.getFullBaseApi().getValue()})`;
}

/**
 * 从sdk-manager获取当前配套的hvigor版本
 *
 * @return string 版本号信息, 如"5.1.0"
 */
function getCurrentModelVersion(): string {
  const hosSdkVersion: HosSdkVersion = getLatestSupportVersion();
  return hosSdkVersion.getPlatformVersion().getVersion();
}

/**
 * 从sdk-manager获取当前配套的最新版本
 *
 * @return string 版本号信息, 如"5.1.0"
 */
function getLatestSupportVersion(): HosSdkVersion {
  return HosVersionMapper.INSTANCE.getLatestSupportVersion();
}
